package ht.ser.impl;

import ht.dao.*;
import ht.domain.*;
import ht.dao.GldwDao;
import ht.dao.LyxxDao;
import ht.dao.HlxxDao;
import ht.domain.Gldw;
import ht.domain.Lyxx;
import ht.domain.Page;
import ht.domain.Hlxx;
import ht.ser.IndexSer;
import org.springframework.stereotype.Service;
import qt.dao.RoleDao;
import qt.dao.UserDao;
import qt.domain.Role;
import qt.domain.User;
import qt.domain.UserShow;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by charmyyy on 2017/10/20.
 */
@Service
public class IndexSerImpl implements IndexSer{
    @Resource(name = "lyxxDao")
    private LyxxDao lyxxDao;

    @Resource(name = "xzqhxxDao")
    private XzqhxxDao xzqhxxDao;

    @Resource(name = "sxxxDao")
    private SxxxDao sxxxDao;

    @Resource(name = "czdjxxDao")
    private CzdjxxDao czdjxxDao;

    @Resource(name = "czflxxDao")
    private CzflxxDao czflxxDao;

    @Resource(name = "ssxmxxDao")
    private SsxmxxDao ssxmxxDao;

    @Resource(name = "czlxxxDao")
    private CzlxxxDao czlxxxDao;
    @Resource(name = "hlxxDao")
    private HlxxDao hlxxDao;

    @Resource(name = "gldwDao")
    private GldwDao gldwDao;

    @Resource(name = "mlxDao")
    private MlxDao mlxDao;

    @Resource(name = "relationDao")
    private RelationDao relationDao;

    @Resource(name = "formulaDao")
    private FormulaDao formulaDao;

    @Resource(name = "dataSourceDao")
    private DataSourceDao dataSourceDao;

    @Resource(name = "userDao")
    private UserDao userDao;

    @Resource(name = "roleDao")
    private RoleDao roleDao;

    public Page<Lyxx> getPageLymc(int start, int limit) {
        Page<Lyxx> page = new Page<Lyxx>(lyxxDao.getLymcCount()+"", lyxxDao.getPageLymc(start,limit));
        return page;
    }

    public List<Lyxx> getAllLyxx(){
        return lyxxDao.getAllLymc();
    }

    public int addLymc(Lyxx h) {
        return lyxxDao.addLymc(h);
    }

    public int upptLymc(Lyxx h) {
        return lyxxDao.upptLymc(h);
    }

    public int deleLymc(String bscd) {
        return lyxxDao.deleLymc(bscd);
    }

    public List<Xzqhxx> getAllXzqhxx() {
        return xzqhxxDao.getAllXzqhxx();
    }

    public Page<XzqhxxShow> getPageXzqhxx(int start, int limit) {
        List<Xzqhxx> list = xzqhxxDao.getPageXzqhxx(start, limit);
        List<XzqhxxShow> llist = new ArrayList<XzqhxxShow>();
        for(Xzqhxx x :list){
            XzqhxxShow s = null;
            if(x.getPaddvcd().equals("-1")){
                //根节点
                s = new XzqhxxShow(x,"");
            }else {
                //FIXME 可能这边会出现 xzqhxxDao.getXzqhxx(x.getPaddvcd())为null的情况！
                s = new XzqhxxShow(x,xzqhxxDao.getXzqhxx(x.getPaddvcd()).getAddvnm());
            }
            llist.add(s);
        }
        return new Page<XzqhxxShow>(xzqhxxDao.getXzqhxxCount()+"",llist);
    }

    public int addXzqhxx(Xzqhxx h) {
        return xzqhxxDao.addXzqhxx(h);
    }

    public int upptXzqhxx(Xzqhxx h) {
        return xzqhxxDao.upptXzqhxx(h);
    }

    public int deleXzqhxx(String addvcd) {
        return xzqhxxDao.deleXzqhxx(addvcd);
    }

    public Page<Czdjxx> getPageCzdjxx(int start, int limit) {
        Page<Czdjxx> page = new Page<Czdjxx>(czdjxxDao.getCzdjxxCount()+"", czdjxxDao.getPageCzdjxx(start,limit));
        return page;
    }

    public List<Czdjxx> getAllCzdjxx(){
        return czdjxxDao.getAllCzdjxx();
    }

    public int addCzdjxx(Czdjxx h) {
        return czdjxxDao.addCzdjxx(h);
    }

    public int upptCzdjxx(Czdjxx h) {
        return czdjxxDao.upptCzdjxx(h);
    }

    public int deleCzdjxx(String stgrdcd) {
        return czdjxxDao.deleCzdjxx(stgrdcd);
    }

    public Page<Sxxx> getPageSxxx(int start, int limit) {
        Page<Sxxx> page = new Page<Sxxx>(sxxxDao.getSxxxCount()+"", sxxxDao.getPageSxxx(start,limit));
        return page;
    }

    public List<Sxxx> getAllSxxx(){
        return sxxxDao.getAllSxxx();
    }

    public int addSxxx(Sxxx h) {
        return sxxxDao.addSxxx(h);
    }

    public int upptSxxx(Sxxx h) {
        return sxxxDao.upptSxxx(h);
    }

    public int deleSxxx(String hncd) {
        return sxxxDao.deleSxxx(hncd);
    }

    public Page<Czflxx> getPageCzflxx(int start, int limit) {
        Page<Czflxx> page = new Page<Czflxx>(czflxxDao.getCzflxxCount()+"", czflxxDao.getPageCzflxx(start,limit));
        return page;
    }

    public List<Czflxx> getAllCzflxx(){
        return czflxxDao.getAllCzflxx();
    }

    public int addCzflxx(Czflxx h) {
        return czflxxDao.addCzflxx(h);
    }

    public int upptCzflxx(Czflxx h) {
        return czflxxDao.upptCzflxx(h);
    }

    public int deleCzflxx(String stclcd) {
        return czflxxDao.deleCzflxx(stclcd);
    }

    public Page<Czlxxx> getPageCzlxxx(int start, int limit) {
        Page<Czlxxx> page = new Page<Czlxxx>(czlxxxDao.getCzlxxxCount()+"", czlxxxDao.getPageCzlxxx(start,limit));
        return page;
    }

    public List<Czlxxx> getAllCzlxxx(){
        return czlxxxDao.getAllCzlxxx();
    }

    public int addCzlxxx(Czlxxx h) {
        return czlxxxDao.addCzlxxx(h);
    }

    public int upptCzlxxx(Czlxxx h) {
        return czlxxxDao.upptCzlxxx(h);
    }

    public int deleCzlxxx(String sttpcd) {
        return czlxxxDao.deleCzlxxx(sttpcd);
    }

    public Page<Ssxmxx> getPageSsxmxx(int start, int limit) {
        Page<Ssxmxx> page = new Page<Ssxmxx>(ssxmxxDao.getSsxmxxCount()+"", ssxmxxDao.getPageSsxmxx(start,limit));
        return page;
    }

    public List<Ssxmxx> getAllSsxmxx(){
        return ssxmxxDao.getAllSsxmxx();
    }

    public int addSsxmxx(Ssxmxx h) {
        return ssxmxxDao.addSsxmxx(h);
    }

    public int upptSsxmxx(Ssxmxx h) {
        return ssxmxxDao.upptSsxmxx(h);
    }

    public int deleSsxmxx(String obitcd) {
        return ssxmxxDao.deleSsxmxx(obitcd);
    }

    //行政区划
    public Page<Hlxx> getPageHlxx(int start, int limit) {
        Page<Hlxx> page = new Page<Hlxx>(hlxxDao.getHlxxCount()+"", hlxxDao.getPageHlxx(start,limit));
        return page;
    }

    public Page<Hlxx> getPageHlxxByNm(int start, int limit, String nm) {
        Page<Hlxx> page = new Page<Hlxx>(hlxxDao.getHlxxCountByNm(nm)+"", hlxxDao.getPageHlxxByNm(start,limit,nm));
        return page;
    }

    public List<Hlxx> getAllHlxx(){
        return  hlxxDao.getAllHlxx();
    }
    public int addHlxx(Hlxx h) {
        return hlxxDao.addHlxx(h);
    }

    public int upptHlxx(Hlxx h) {
        return hlxxDao.upptHlxx(h);
    }

    public int deleHlxx(String rvcd) {
        return hlxxDao.deleHlxx(rvcd);
    }

    //管理单位
    public Page<Gldw> getPageGldw(int start, int limit) {
        Page<Gldw> page = new Page<Gldw>(gldwDao.getGldwCount()+"", gldwDao.getPageGldw(start,limit));
        return page;
    }

    public Page<Gldw> getPageGldwByNm(int start, int limit,String nm) {
        Page<Gldw> page = new Page<Gldw>(gldwDao.getGldwCountByNm(nm)+"", gldwDao.getPageGldwByNm(start,limit,nm));
        return page;
    }

    public List<Gldw> getAllGldw(){
        return gldwDao.getAllGldw();
    }

    public int addGldw(Gldw h) {
        return gldwDao.addGldw(h);
    }

    public int upptGldw(Gldw h) {
        return gldwDao.upptGldw(h);
    }

    public int deleGldw(String admagcd) {
        return gldwDao.deleGldw(admagcd);
    }

    public Page<Mlx> getPageMlx(int start, int limit) {
        Page<Mlx> page = new Page<Mlx>(mlxDao.getMlxCount()+"", mlxDao.getPageMlx(start,limit));
        return page;
    }

    public List<Mlx> getAllMlx(){
        return mlxDao.getAllMlx();
    }

    public int addMlx(Mlx h) {
        return mlxDao.addMlx(h);
    }

    public int upptMlx(Mlx h) {
        return mlxDao.upptMlx(h);
    }

    public int deleMlx(String tycd) {
        return mlxDao.deleMlx(tycd);
    }

    public Page<Relation> getPageRelation(int start,int limit){
        Page<Relation> page = new Page<Relation>(relationDao.getRelationCount()+"",relationDao.getPageRelation(start,limit));
        return page;
    }

    public List<Relation> getAllRelation(){
        return relationDao.getAllRelation();
    }

    public int addRelation(Relation relation){
        return relationDao.addRelation(relation);
    }

    public int upptRelation(Relation relation){
        return relationDao.upptRelation(relation);
    }

    public int deleRelation(String rela){
        return relationDao.deleRelation(rela);
    }

    public List<Formula> getAllFormula(){
        return formulaDao.getAllFormula();
    }

    public Page<FormulaShow> getPageFormula(int start,int limit){
        List<Formula> list = formulaDao.getPageFormula(start, limit);
        List<FormulaShow> llist = new ArrayList<FormulaShow>();
        for(Formula f :list){
            FormulaShow fs = null;
            //FIXME 可能这边会出现 xzqhxxDao.getXzqhxx(x.getPaddvcd())为null的情况！
            fs = new FormulaShow(f,dataSourceDao.getDataSourceName(f.getData_source_id()));
            llist.add(fs);
        }
        return new Page<FormulaShow>(formulaDao.getFormulaCount()+"",llist);
    }

    public int addFormula(Formula formula){
        return formulaDao.addFormula(formula);
    }

    public int upptFormula(Formula formula){
        return formulaDao.upptFormula(formula);
    }

    public int deleFormula(int param_id){
        return formulaDao.deleFormula(param_id);
    }

    public List<DataSource> getAllDataSource(){
        return dataSourceDao.getAllDataSource();
    }


    public Page<UserShow> getPageUser(int start, int limit){
        List<User> list = userDao.getPageUser(start, limit);
        List<UserShow> llist = new ArrayList<UserShow>();
        for(User u :list){
            UserShow us = null;
            //FIXME 可能这边会出现 xzqhxxDao.getXzqhxx(x.getPaddvcd())为null的情况！
            us = new UserShow(u,roleDao.getRoleName(u.getRolecd()));
            llist.add(us);
        }
        return new Page<UserShow>(userDao.getUsersCount()+"",llist);
    }

//    public Page<User> getPageUser(int start, int limit){
//        Page<User> page = new Page<User>(userDao.getUsersCount()+"",userDao.getPageUser(start,limit));
//        return page;
//    }
    public List<User> getAllUser(){
        return userDao.getAllUsers();
    }

    public int addUser(User user){
        return userDao.addUser(user);
    }

    public int upptUser(User user){
        return userDao.upptUser(user);
    }

    public int deleUser(String ucode){
        return userDao.deleUser(ucode);
    }

    public Page<Role> getPageRole(int start, int limit){
        Page<Role> page = new Page<Role>(roleDao.getRoleCount()+"",roleDao.getPageRole(start,limit));
        return page;
    }

    public List<Role> getAllRole(){
        return roleDao.getAllRole();
    }

    public int addRole(Role role){
        return roleDao.addRole(role);
    }

    public int upptRole(Role role){
        return roleDao.upptRole(role);
    }

    public int deleRole(String rolecd){
        return roleDao.deleRole(rolecd);
    }
}
